/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.nanosn.coffeemaker.server.restlet.gae;

import java.io.IOException;
import java.io.OutputStream;
import org.restlet.data.MediaType;
import org.restlet.representation.OutputRepresentation;

/**
 *
 * @author selkhateeb
 */
public class GwtRpcRepresentation extends OutputRepresentation {

    private static final String ATTACHMENT = "attachment";
    private byte[] bytes;

    public GwtRpcRepresentation(byte[] bytes) {
        super(MediaType.APPLICATION_JSON);
        this.setSize(bytes.length);
        //this.getEncodings().add(Encoding.GZIP);
        this.bytes = bytes;
        this.setDownloadName(ATTACHMENT);

        // Send the reply.
        //
//		response.setContentLength(responseBytes.length);
//		response.setContentType(CONTENT_TYPE_APPLICATION_JSON_UTF8);
//		response.setStatus(HttpServletResponse.SC_OK);
//		response.setHeader(CONTENT_DISPOSITION, ATTACHMENT);
//		response.getOutputStream().write(responseBytes);
    }

    @Override
    public void write(OutputStream outputStream) throws IOException {
        outputStream.write(bytes);
        outputStream.flush();
        outputStream.close();
    }
}
